
#include "TinyTCPServer.h"
#include "..\TinyVoiceCardServer\TinyVoiceCardServerDefine.h"
#include "..\TinyVoiceCardServer\TinyTCPIF.h"
#include "TinySanhuiLibDefine.h"
#include "DeviceStateRinging.h"
#include "Device.h"


namespace DeviceStates {
	CDeviceStateRinging::CDeviceStateRinging(void)
	{
	}

	CDeviceStateRinging::~CDeviceStateRinging(void)
	{
	}

	void CDeviceStateRinging::ProcessReceivedMsg(CTinyMsg &inMsg,CTinyMsg &OutMsg)
	{
		switch(inMsg.getMsgIndex())
		{
		case VOICECARD_ACTION:
			switch(inMsg.getMsgItem())
			{
			case VOICECARD_PICKUP:
				{
					//pickup and upload connected msg
					std::string moduleName,deviceType,deviceID;

					inMsg.getDefaultParamByIndex(VOICECARD_PICKUP_MODULENAME,moduleName);
					inMsg.getDefaultParamByIndex(VOICECARD_PICKUP_DEVICEID,deviceID);
					inMsg.getDefaultParamByIndex(VOICECARD_PICKUP_DEVICETYPE,deviceType);

					if(this->deviceHandle->pickup() == true)
					{
						g_Logger.log(debug1,"call picked up from "+deviceID);
						//we should turn to connected state;
						g_TinyTCPIF.RaiseConnectedEvt(deviceID,deviceType);
						changeState(DEVICE_STATE_CONNECTED);
					}
					else
					{
						g_Logger.log(debug1,"call pickup failed"+deviceID);
					}
				}break;
			default:
				break;
			};
			break;
		};
		
	}

	int CDeviceStateRinging::CardCallBackProc(WORD wEvent, DWORD dwParam)
	{
		switch(wEvent) 
		{
		case E_SYS_TIMEOUT://Timer event
			break;
		case E_CHG_ChState:
			{
				switch(int(dwParam&0xFFFF))
				{
					//call start
				case S_CALL_RINGING:
					{

					}
					break;
				};
			}

		default:
			break;
		};
		return 0;
	}
}
